using System;
using System.Collections.Generic;

using Csla;

using EntModApp.EntServices.Business;

using DemoApp.DataAccess;

namespace DemoApp.BusinessLayer 
{
  public partial class CslaSubjectInfo : 
    ReadOnlyBase<CslaSubjectInfo>,
    ISubject
  {
    #region [ Business Properties ]

    public static PropertyInfo<Guid> SubjectIdPropertyInfo = RegisterProperty(new PropertyInfo<Guid>("SubjectId"));
    public Guid SubjectId 
    { 
      get
      {
        return ReadProperty(SubjectIdPropertyInfo);
      }
      private set
      {
        LoadProperty(SubjectIdPropertyInfo, value);
      }
    }

    public static PropertyInfo<string> UrlPropertyInfo = RegisterProperty(new PropertyInfo<string>("Url"));
    public string Url 
    { 
      get
      {
        return ReadProperty(UrlPropertyInfo);
      }
      private set
      {
        LoadProperty(UrlPropertyInfo, value);
      }
    }

    public static PropertyInfo<string> TitlePropertyInfo = RegisterProperty(new PropertyInfo<string>("Title"));
    public string Title 
    { 
      get
      {
        return ReadProperty(TitlePropertyInfo);
      }
      private set
      {
        LoadProperty(TitlePropertyInfo, value);
      }
    }

    public static PropertyInfo<string> DescriptionPropertyInfo = RegisterProperty(new PropertyInfo<string>("Description"));
    public string Description 
    { 
      get
      {
        return ReadProperty(DescriptionPropertyInfo);
      }
      private set
      {
        LoadProperty(DescriptionPropertyInfo, value);
      }
    }

    public static PropertyInfo<string> ImageUrlPropertyInfo = RegisterProperty(new PropertyInfo<string>("ImageUrl"));
    public string ImageUrl 
    { 
      get
      {
        return ReadProperty(ImageUrlPropertyInfo);
      }
      private set
      {
        LoadProperty(ImageUrlPropertyInfo, value);
      }
    }

    public static PropertyInfo<DateTime> CreateDatePropertyInfo = RegisterProperty(new PropertyInfo<DateTime>("CreateDate"));
    public DateTime CreateDate 
    { 
      get
      {
        return ReadProperty(CreateDatePropertyInfo);
      }
      private set
      {
        LoadProperty(CreateDatePropertyInfo, value);
      }
    }

    public static PropertyInfo<DateTime> ModifyDatePropertyInfo = RegisterProperty(new PropertyInfo<DateTime>("ModifyDate"));
    public DateTime ModifyDate 
    { 
      get
      {
        return ReadProperty(ModifyDatePropertyInfo);
      }
      private set
      {
        LoadProperty(ModifyDatePropertyInfo, value);
      }
    }

    public static PropertyInfo<bool> IsDisabledPropertyInfo = RegisterProperty(new PropertyInfo<bool>("IsDisabled"));
    public bool IsDisabled 
    { 
      get
      {
        return ReadProperty(IsDisabledPropertyInfo);
      }
      private set
      {
        LoadProperty(IsDisabledPropertyInfo, value);
      }
    }

    public static PropertyInfo<CslaUserInfo> CreatorPropertyInfo = RegisterProperty(new PropertyInfo<CslaUserInfo>("Creator"));
    public CslaUserInfo Creator 
    { 
      get
      {
        return ReadProperty(CreatorPropertyInfo);
      }
      set
      {
        LoadProperty(CreatorPropertyInfo, value);
      }
    }

    public static PropertyInfo<CslaUserInfoCollection> EditorsPropertyInfo = RegisterProperty(new PropertyInfo<CslaUserInfoCollection>("Editors"));
    public CslaUserInfoCollection Editors 
    { 
      get
      {
        return ReadProperty(EditorsPropertyInfo);
      }
      private set
      {
        LoadProperty(EditorsPropertyInfo, value);
      }
    }

    public static PropertyInfo<CslaSubjectInfo> ParentSubjectPropertyInfo = RegisterProperty(new PropertyInfo<CslaSubjectInfo>("ParentSubject"));
    public CslaSubjectInfo ParentSubject 
    { 
      get
      {
        return ReadProperty(ParentSubjectPropertyInfo);
      }
      set
      {
        LoadProperty(ParentSubjectPropertyInfo, value);
      }
    }

    public static PropertyInfo<CslaSubjectInfoCollection> SubSubjectsPropertyInfo = RegisterProperty(new PropertyInfo<CslaSubjectInfoCollection>("SubSubjects"));
    public CslaSubjectInfoCollection SubSubjects 
    { 
      get
      {
        return ReadProperty(SubSubjectsPropertyInfo);
      }
      private set
      {
        LoadProperty(SubSubjectsPropertyInfo, value);
      }
    }

    #endregion [ Business Properties ]

    #region [ Factory Methods ]
    protected internal static CslaSubjectInfo GetSubjectInfo(Subject data, SubjectLoadSettings loadSettings)
    {
      if (data == null) throw new ArgumentNullException("data");
      if (loadSettings == null) throw new ArgumentNullException("loadSettings");
      CslaSubjectInfo result = new CslaSubjectInfo();
      result.FetchSubject(data, loadSettings);
      return result;
    }

    private static int ForceInitField = 0;
    protected CslaSubjectInfo() 
    {
      ForceInitField = 1;
    }
    #endregion [ Factory Methods ]

    #region [ Data Access ]
    protected void FetchSubject(Subject data, SubjectLoadSettings loadSettings)
    {
      FetchSubjectData(data, loadSettings);
      FetchSubjectChildren(data, loadSettings);
    }

    protected void FetchSubjectData(Subject data, SubjectLoadSettings loadSettings)
    {
      this.SubjectId = data.SubjectId;
      this.Url = data.Url;
      this.Title = data.Title;
      this.Description = data.Description;
      this.ImageUrl = data.ImageUrl;
      this.CreateDate = data.CreateDate;
      this.ModifyDate = data.ModifyDate;
      this.IsDisabled = data.IsDisabled;
    }

    protected void FetchSubjectChildren(Subject data, SubjectLoadSettings loadSettings)
    {
      if (loadSettings.Inclusion.IncludeEditors)
        this.Editors = CslaUserInfoCollection.GetUserInfoCollection(data.Editors, loadSettings.Inclusion.IncludedEditorsSettings);
      if (loadSettings.Inclusion.IncludeSubSubjects)
        this.SubSubjects = CslaSubjectInfoCollection.GetSubjectInfoCollection(data.SubSubjects, loadSettings.Inclusion.IncludedSubSubjectsSettings);
    }
    #endregion [ Data Access ]

    #region [ Explicit ISubject implementation ]

    Guid ISubject.SubjectId
    {
      get { return this.SubjectId; }
    }

    string ISubject.Url
    {
      get { return this.Url; }
      set
      {
        throw new NotSupportedException();
      }
    }

    string ISubject.Title
    {
      get { return this.Title; }
      set
      {
        throw new NotSupportedException();
      }
    }

    string ISubject.Description
    {
      get { return this.Description; }
      set
      {
        throw new NotSupportedException();
      }
    }

    string ISubject.ImageUrl
    {
      get { return this.ImageUrl; }
      set
      {
        throw new NotSupportedException();
      }
    }

    DateTime ISubject.CreateDate
    {
      get { return this.CreateDate; }
      set
      {
        throw new NotSupportedException();
      }
    }

    DateTime ISubject.ModifyDate
    {
      get { return this.ModifyDate; }
      set
      {
        throw new NotSupportedException();
      }
    }

    bool ISubject.IsDisabled
    {
      get { return this.IsDisabled; }
      set
      {
        throw new NotSupportedException();
      }
    }

    IUser ISubject.Creator
    { 
      get
      {
        return this.Creator;
      }
      set
      {
        throw new NotSupportedException();
      }
    }

    IBusinessObjectCollection<IUser> ISubject.Editors
    { 
      get
      {
        return this.Editors;
      }
    }

    ISubject ISubject.ParentSubject
    { 
      get
      {
        return this.ParentSubject;
      }
      set
      {
        throw new NotSupportedException();
      }
    }

    IBusinessObjectCollection<ISubject> ISubject.SubSubjects
    { 
      get
      {
        return this.SubSubjects;
      }
    }


    bool IBusinessObject.IsReadonly
    {
      get { return true; }
    }

    bool IBusinessObject.IsDirty
    {
      get { return false; }
    }

    #endregion [ Explicit ISubject implementation ]
  }
}
